<template>
	<view class="universal-detail">
		<view class="universal-detail-top">
			<view class="universal-detail-top-time">
				<text class="universal-detail-top-title">审核</text>
			</view>
		</view>

		<view class="universal-detail-cont">
			<van-form class="universal-detail-form" @submit="onSubmit" label-width="140rpx">
				<van-cell-group>
					<van-field name="checkboxGroup" required colon label="审核结果"
						:rules="[{ required: true, message: '请选择审核结果' }]">
						<template #input>
							<van-radio-group v-model="form.audit" direction="horizontal">
								<van-radio :name="0">通过</van-radio>
								<van-radio :name="1">不通过</van-radio>
							</van-radio-group>
						</template>
					</van-field>
					<van-field v-model="form.remark" :required="form.audit === 1" rows="4" colon autosize
						type="textarea" label="审核理由" show-word-limit maxlength="200"
						:rules="[{ required: form.audit === 1, message: '请输入审核理由' }]" placeholder="请输入审核理由" />
				</van-cell-group>

				<view class="universal-detail-bottom">
					<van-button class="universal-detail-bottom-button universal-detail-bottom-button-cancel"
						type="default" @click="routeBack">取消</van-button>
					<van-button class="universal-detail-bottom-button universal-detail-bottom-button-sumbit"
						type="primary" native-type="submit">提交</van-button>
				</view>
			</van-form>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';

	import {
		apiAlertSuperviseAudit
	} from '@/api/warningTodo';

	const model = defineModel();
	const emit = defineEmits(['confirm']);
	const form = ref({});

	const onSubmit = () => {
		uni.showLoading({
			title: '提交中',
			mask: true
		});

		apiAlertSuperviseAudit(form.value).then(res => {
			uni.showToast({
				title: '提交成功',
				icon: 'success',
			});
			emit('confirm');
		}).finally(() => {
			uni.hideLoading();
		})
	};

	const routeBack = () => {
		uni.navigateBack({
			delta: 1
		});
	}

	form.value.alertSuperviseId = model.value.alertSuperviseId || '';
</script>

<style lang="scss" scoped>
	@import '@/assets/universal-detail.scss';
	@import '@/assets/form.scss';
</style>